package com.example.fushuang.balabala.fragment;


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import com.example.fushuang.balabala.R;
import com.example.fushuang.balabala.client.ClientAPI;
import com.example.fushuang.balabala.model.LiveHost;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * A simple {@link Fragment} subclass.
 */
public class LiveFragment extends BaseFragment implements SwipeRefreshLayout.OnRefreshListener {


    @BindView(R.id.live_viewPager)
    ViewPager mViewPager;
    @BindView(R.id.live_recycle)
    RecyclerView mRecycle;
    @BindView(R.id.live_swipeRefresh)
    SwipeRefreshLayout mSwipeRefresh;

    private List<LiveHost.DataBean.RecommendDataBean.LivesBean> mLives;

    public LiveFragment() {
        // Required empty public constructor
    }

    @Override
    public String getFragmentTitle() {
        return "直播";
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //注册事件订阅者
        EventBus.getDefault().register(this);
    }

    @Override
    public void onDestroy() {

        EventBus.getDefault().unregister(this);
        super.onDestroy();
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_live, container, false);
        ButterKnife.bind(this, view);
        mSwipeRefresh.setOnRefreshListener(this);
        return view;
    }


    @Override
    public void onRefresh() {
        ClientAPI.getLiveHostJSonAsync();
    }
    @Subscribe
    public void onReceiveLiveJson(LiveHost liveHost){
        int code = liveHost.getCode();
        if (code==0){
            mLives = liveHost.getData().getRecommend_data().getLives();

        }
    }

}
